package edu.cibertec.sicsolutions.vfs.domain.votacion;

import org.apache.log4j.Logger;

import edu.cibertec.sicsolutions.exception.DaoException;
import edu.cibertec.sicsolutions.exception.DomainException;
import edu.cibertec.sicsolutions.vfs.dao.votacion.PaisDao;
import edu.cibertec.sicsolutions.vfs.spring.SpringContext;

import java.io.Serializable;
import java.util.Map;

/**
 * Domain Object of table PAIS 
 * @author enrique.vargas
 *
 */
public class Pais implements Serializable {

	private static final Logger log = Logger.getLogger(Pais.class);
	private static final PaisDao paisDao = (PaisDao)SpringContext.get(PaisDao.class);	
 
	
	public Pais(){
	}
	
	public Pais(String codigo){		
		this.codigo = codigo;
	}
	
	
	private String codigo;
	/**
	 * Column: NOMBRE, DataType: varchar
	 */
	private String nombre;
	/**
	 * Column: REGION, DataType: varchar
	 */
	private String region;

		public String getCodigo(){
		return codigo;
	}
	public void setCodigo(String codigo){
		this.codigo = codigo;
	}
	public String getNombre(){
		return nombre;
	}
	public void setNombre(String nombre){
		this.nombre = nombre;
	}
	public String getRegion(){
		return region;
	}
	public void setRegion(String region){
		this.region = region;
	}

	/**
	 * Get Object of Data Base By PK	 
	 * @param pais
	 * @return
	 * @throws DomainException
	 */
	public static Pais getPaisByPk(Pais pais) throws DomainException{
		try{
			return paisDao.getPaisByPk(pais);
		} catch (DaoException e) {
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		} catch (Exception e){
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		}		
	}
	
	/**
	 * Save Object
	 * @param pais
	 * @return
	 * @throws DomainException
	 */	
	public static void insertPais (Pais pais) throws DomainException{
		try{
			paisDao.insertPais(pais);
		} catch (DaoException e) {
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		} catch (Exception e){
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		}		
	}
	
	/**
	 * Update Object 
	 * @param pais
	 * @return
	 * @throws DomainException
	 */
	public static void updatePais (Pais pais) throws DomainException{		
		try{
			paisDao.updatePais(pais);
		} catch (DaoException e) {
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		} catch (Exception e){
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		}
	}
	
	/**
	 * Update Object 
	 * @param pais
	 * @return
	 * @throws DomainException
	 */
	public static void updatePaisByMap (Map map) throws DomainException{		
		try{
			paisDao.updatePaisByMap(map);
		} catch (DaoException e) {
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		} catch (Exception e){
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		}
	}
	
	/**
	 * Delete Object	 
	 * @param pais
	 * @return
	 * @throws DomainException
	 */
	public static void deletePaisByPk(Pais pais) throws DomainException{		
		try{
			paisDao.deletePaisByPk(pais);
		} catch (DaoException e) {
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		} catch (Exception e){
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		}
	}
	
	/**
	 * Find Object By Filters
	 * @param pais
	 * @return
	 * @throws DomainException
	 */
	public static Pais[] findPaisByClass(Pais pais) throws DomainException{		
		try{
			return paisDao.findPaisByClass(pais);
		} catch (DaoException e) {
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		} catch (Exception e){
			log.error(e.getMessage(), e);
			throw new DomainException(e.getMessage(), e);
		}
	}
 
}